WEBVTT

00:02.190 --> 00:03.180
Hello and welcome back.

00:03.180 --> 00:05.820
So in the last session we learned about four loops.

00:05.820 --> 00:12.300
And now in this session we want to increase the functionality or the flexibility of our followers by

00:12.300 --> 00:14.830
introducing the key words continue.

00:14.850 --> 00:16.700
Break and pass.

00:16.710 --> 00:26.750
So first of all let's create a list L with the elements 1 3 5 7 10 11 13 14 and 15.

00:26.770 --> 00:30.800
What we want to do now we want to find the first even element an hour.

00:31.140 --> 00:37.110
So what does even means that even means that I am modulo 2 equals zero.

00:37.110 --> 00:40.560
We are introducing a fault of every element an error.

00:40.590 --> 00:46.190
And then we are having an if statement if I model two is zero.

00:46.200 --> 00:52.090
Then please print me the first even elements X and this element is odd.

00:52.140 --> 00:59.610
Then please print me the elements at so let's have a look what we get here.

01:00.290 --> 01:01.010
And here we get.

01:01.010 --> 01:01.370
Okay.

01:01.370 --> 01:04.350
One is up 3 Assad fighters not seven Assad.

01:04.460 --> 01:07.940
Then the first element is 10 first even element.

01:07.940 --> 01:12.770
But now you can see that iteration goes on until the very last element 15.

01:12.770 --> 01:19.550
But what we actually wanted we wanted to determine the first element that is even and we do not care

01:19.550 --> 01:24.230
about all any other elements that comes after the first even element.

01:24.470 --> 01:29.050
And therefore we can here include the keyboard break.

01:29.150 --> 01:31.200
So let's execute again.

01:31.350 --> 01:36.610
They can see that the iteration stops once we have reached the first even element.

01:36.630 --> 01:40.220
So what Python is doing here it iterate over the list.

01:40.220 --> 01:47.780
And once our condition is met once so tense our first even element we print it and then break means

01:47.810 --> 01:50.420
that we completely stop the iteration here.

01:50.420 --> 01:50.890
All right.

01:50.990 --> 01:56.120
We are only interested in the first even element we do not care about what elements so we don't want

01:56.120 --> 02:00.650
to print out that let's for example say one is up and.

02:00.810 --> 02:01.010
Yeah.

02:01.030 --> 02:08.330
What we can do B can instead of having here the action print the element is what we can just say pass

02:08.330 --> 02:09.150
or do nothing.

02:09.270 --> 02:19.030
If an element is not and they can see it the only message the only result we get is that the first element

02:19.030 --> 02:27.640
is 10 and even we we don't actually need here hear the complete s statement so if you just delete it

02:28.950 --> 02:30.010
then it also works.

02:30.450 --> 02:33.870
So now maybe you're asking yourself why do we need the pass statement.

02:33.870 --> 02:37.180
I mean here we just deleted the whole s statement.

02:37.180 --> 02:40.570
But let's assume we want to have the if statement the other way around.

02:40.560 --> 02:44.410
So first of all we want to check if the element is art.

02:44.430 --> 02:47.030
And in this case we just want to do nothing.

02:47.160 --> 02:55.740
And if it's not art we want to print the very first even element and let's run the cell here and you

02:55.740 --> 03:00.790
see it still works because here we are saying if the element is art then pass.

03:01.140 --> 03:02.190
But what if we.

03:02.280 --> 03:06.660
But what if we completely cross out paths and just have nothing here.

03:06.660 --> 03:09.150
So if the element is up I do not care.

03:09.180 --> 03:17.950
I'm not interested in again error message so far a statement we always have to define an action and

03:17.950 --> 03:23.030
if you want to do nothing the past keyword is just a fill about which we need.

03:23.140 --> 03:24.880
Otherwise we get an error message.

03:24.880 --> 03:29.490
All right so we'll have a better understanding how the path keyword works.

03:29.560 --> 03:31.590
We are just here having the same code.

03:31.600 --> 03:35.010
But after our past keyword we say OK.

03:35.040 --> 03:44.050
Even if our element is Art please print me the element and then we get one two three five seven and

03:44.050 --> 03:46.960
then the first element even element is 10.

03:47.140 --> 03:52.740
So maybe you want to print out all other elements but what if we don't want to print out all elements

03:52.760 --> 03:58.270
so we are checking if an element is up and if it's art we are just wanting to go to the next element

03:58.960 --> 04:02.140
and they are the keyword continue comes in to play.

04:02.140 --> 04:10.850
So instead of having pass here we have continue and still we have printed.

04:10.890 --> 04:14.340
But let's look if the behavior is different.

04:14.820 --> 04:18.830
And here you can see we are just having the statement the first even element is 10.

04:18.820 --> 04:20.590
So what Python does here.

04:20.610 --> 04:29.220
It checks whether an element is odd and if it's art continuum means please go to the next element do

04:29.220 --> 04:32.190
nothing and go to the next element even don't print it.

04:32.190 --> 04:35.770
So that's actually the difference between past and continue.

04:35.910 --> 04:42.180
So continuous is a keyword saying that please go to the next element and pass is just a keyword for

04:42.220 --> 04:43.500
please do nothing.

04:43.500 --> 04:45.050
And to make it a little bit more clear.

04:45.060 --> 04:49.010
So let's assume we still want to find the first even element.

04:49.050 --> 04:51.380
But for whatever reason we want to exclude 10.

04:51.390 --> 04:53.010
As a result that's the here.

04:53.010 --> 04:54.840
So this is the code we already know.

04:54.840 --> 05:03.360
So if two is even then please print the first even elements x y z and then please break the if you want

05:03.360 --> 05:05.140
to exclude that we get 10.

05:05.190 --> 05:10.830
We have to introduce another if statement saying if I equals 10 please continue.

05:10.830 --> 05:15.780
So please ignore if 10 this and minus because I don't want to have 10 as a result

05:18.980 --> 05:22.010
so this gets me here 14 as a final result.

05:22.020 --> 05:26.460
So the first even element is 14 because I just ignore 10.

05:26.480 --> 05:28.660
All right so this is it for the time being.

05:28.660 --> 05:31.010
And I hope to you in the next session by.
